<!DOCTYPE html>
<html lang="zh_CN">
<head>
<#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/jqueryForm/jquery.form.js"></script>

    <script>
        $(function () {
            //找打添加和编辑按钮绑定点击事件
            $(".inputBtn").click(function () {
                //1.清空模态框中数据
                $("#editForm input").val("");
                //2.获取当前按钮中,data-json的值
                var json = $(this).data("json");
                console.log(json);
                if (json) {
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='name']").val(json.name);
                }
                //3.显示模态框
                $("#inputModal").modal("show");
            });

            //把当前表单提交改为ajax提交
            $("#editForm").ajaxForm(function (data) {
                reload();
            });
            //给表单提交按钮绑定点击事件
            $(".submitBtn").click(function () {
                $("#editForm").submit();
            });

            //给删除按钮绑定点击事件
            $(".deleteBtn").click(function () {
                var url = $(this).data("url");
                $.messager.confirm("温馨提示", "亲,确定要删除吗?", function () {
                    $.get(url, function (data) {
                        //记得使用分页合理化
                        reload();
                    });
                });
            });
        });
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#-- 往数据模型中添加一个属性 -->
            <#assign menu="productSort"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">商品分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/productSort/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>商品分类</th>
                    <th>操作</th>
                </tr>
                <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                <tr>
                    <td>${entity_index + 1}</td>
                    <td>${entity.name}</td>
                    <td>
                    <#--当前按钮中绑定自定义属性,内容是当前数据的json字符串-->
                        <a class="btn btn-info btn-xs inputBtn" role="button" data-json='${entity.json}'>
                            <span class="glyphicon glyphicon-pencil"></span>编辑
                        </a>
                        <a data-url="/productSort/delete.do?id=${entity.id}" class="btn btn-danger btn-xs deleteBtn">
                            <span class="glyphicon glyphicon-trash"></span>删除
                        </a>
                    </td>
                </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>

<!-- 添加和编辑的模态框,必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/productSort/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="${(entity.id)!}" name="id">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">商品分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name"
                                   value="${(entity.name)!}" placeholder="请输入商品分类名称">
                        </div>
                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span>关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
            </div>
        </div>
    </div>
</div>


</body>
</html>